<template>
	<view>
		<view class="editaddress">
			<view class="content">
				<view class="row">
					<view class="nominal">收货人</view>
					<view class="input"><input placeholder="请输入收货人姓名" v-model="addressData.name" type="text" />
					</view>
				</view>
				<view class="row">
					<view class="nominal">电话号码</view>
					<view class="input"><input placeholder="请输入收货人电话号码" v-model="addressData.phone" type="number"
							maxlength="11" /></view>
				</view>
				<view class="row">
					<view class="nominal">所在地区</view>
					<view class="input selectcity" @tap="openPicker">
						<input placeholder="请选择省市区" disabled type="text" v-model="addressData.address" />
						<image src="/static/right.png" class="rights"></image>
					</view>
				</view>
				<view class="row">
					<view class="nominal">详细地址</view>
					<view class="input">
						<textarea style="font-size: 28upx;" v-model="addressData.moreAddres" auto-height="true"
							placeholder="输入详细地址" v-if="show == false"></textarea>
					</view>
				</view>
				<view class="row">
					<view class="nominal" style="color: 666;margin-top: 10upx;">设为默认地址</view>
					<view class="input switch">
						<switch :color="colors" style="transform:scale(0.8)" @change="switchChange"
							:checked="addressData.isdefult == 1"></switch>
					</view>
				</view>
			</view>
			<view class="save">
				<view class="btn" :style="'background:' + colors">保存地址</view>
			</view>

		</view>
		<u-picker
			:show="addrPickerShow"
			ref="uPicker"
			:columns="columns"
			keyName="text"
			@confirm="onConfirm"
			@cancel="onCancel"
		></u-picker>
	</view>
</template>

<script>
	import address from '../../component/address.json';
	export default {
		data() {
			return {
				addrPickerShow:false,
				colors:"#ff0000",
				columns: [], //省份数据显示，三级联动需要三维数组，展示初始数据
				columnData: [], //市数据
				columnDatas: [], //区地址
				addressData: {
					name: '',
					phone: '',
					address: '',
					moreAddres: '',
					isdefult: 0
				}
			};
		},
		created(){
			this.initCity();
		},
		methods: {
			initCity(){
				let province = []; //初始数据需要展示的省份
				let province1 = [{
					name: '市辖区',
					code: '1101'
				}]; 
				let province2 = []; //初始数据需要展示的区域数据，也即是 北京市市辖区内的区
				address.forEach(item => {
					province.push(item.name);
				});
				address[0].children[0].children.forEach(item => {
					province2.push(item.name);
				});
				//省数据 因为要做数据初始化，所以是三维数组 
				// 数据格式 [ [所有的省份数据:{},{}] , [第一个省份下的所有的市:{},{},{}] , [第一个市下面所有的区:{},{},{}] ]
				this.columns.push(province);
				this.columns.push(province1);
				this.columns.push(province2);
				// 市数据数组，筛选address.json文件，将全国所有省下面的市数据放入数组
				// 格式[ [第一个省下面所有市,{},{},{}] , [第二个省下面所有市{},{},{}] , [第三个省下面所有市{},{},{}] ] 注意，以上的第一第二对应着 columns[0] 的数据
				address.forEach(item => {
					let city = [];
					item.children.forEach(item1 => {
						city.push(item1.name);
					});
					this.columnData.push(city);
				});
				//区数据数组
				//数据格式: [ 所有省下面所有市的所有区 [ 第一个省下面所有市的区:[ [第一个省下面第一个市的所有区] , [第一个省下面第二个市的所有区] ,]   ,   [ 第二个省下面所有市的区:[ [第二个省下面第一个市的所有区] , [第二个省下面第二个市的所有区] ,]   ]
				let area = [];
				address.forEach((item, index) => {
					let area1 = []; //省下面所有市的初始化
					item.children.forEach(item1 => {
						area = []; //市下面的区初始化
						item1.children.forEach(item2 => {
							area.push(item2.name);
						});
						area1.push(area); // 每循环一个市，添加该市下面的所有区
					});
					this.columnDatas.push(area1); // 每循环一个省，添加该省下面的所有市
				});
			},
			openPicker() {
				this.addrPickerShow=true;
			},
			onConfirm(){
				
			},
			onCancel(){
				this.addrPickerShow=false;
			},
		}
	};
</script>
<style lang="scss" scoped>
	.save {
		position: fixed;
		bottom: 0;
		width: 100%;
		height: 120upx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.save view {
		display: flex;
	}

	.save .btn {
		box-shadow: 0upx 5upx 10upx rgba(0, 0, 0, 0.4);
		width: 70%;
		height: 80upx;
		border-radius: 80upx;
		background-color: #f23a3a;
		color: #fff;
		justify-content: center;
		align-items: center;
		font-size: 30upx;
		margin-bottom: 60px;
	}

	.save .btn .icon {
		height: 80upx;
		color: #fff;
		font-size: 30upx;
		justify-content: center;
		align-items: center;
	}

	.content {
		display: flex;
		flex-wrap: wrap;
		margin-top: 40upx;
	}

	.content view {
		display: flex;
	}

	.content .row {
		width: 92%;
		margin: 0 4%;
		border-bottom: solid 1upx #eee;
	}

	.content .row .nominal {
		width: 30%;
		height: 80upx;
		font-size: 28upx;
		font-family: Droid Sans Fallback;
		font-weight: 400;
		color: rgba(51, 51, 51, 1);
		align-items: center;
	}

	.content .row .input {
		width: 70%;
		padding: 20upx 0;
		align-items: center;
		font-size: 28upx;

	}

	.content .row .input input {
		font-size: 28upx;
		color: #333333;
	}

	.content .row .switch {
		justify-content: flex-end;
	}

	.content .row .input textarea {
		min-height: 40upx;
		line-height: 40upx;
	}

	.content .del_box {
		width: 100%;
		display: block;
		overflow: hidden;
		margin-right: 30upx;
	}

	.content .del {
		width: 240upx;
		height: 80upx;
		float: right;
		justify-content: center;
		align-items: center;
		font-size: 28upx;
		color: #F23A3A;
		margin: 0 auto;
		margin-top: 50upx;
		border-radius: 38upx;
		background-color: rgba(255, 0, 0, 0.05);
		border-bottom: solid 1upx #eee;
	}

	.selectcity input {
		width: 90%;
	}

	.selectcity image {
		width: 40upx;
		height: 40upx;
		float: right;
	}
</style>